#!/usr/bin/env python
# -*- coding:utf-8 -*-

# 看代码写结果
'''
v1 = [1,2,3,4,5]
v2 = [v1,v1,v1]

v1.append(6)
print(v1)
print(v2)
'''
#[1,2,3,4,5,6]
#[[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6]]


# 2题

# 看代码写结果
'''
v1 = [1,2,3,4,5]
v2 = [v1,v1,v1]

v2[1][0] = 111
v2[2][0] = 222
print(v1)
print(v2)
'''
#[222,2,3,4,5]
#[[222,2,3,4,5],[222,2,3,4,5],[222,2,3,4,5]]

'''
#  3.看代码写结果，并解释每一步的流程。
v1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
v2 = {}

for item in v1:
    if item < 6:  # 如果大于6则执行以下内容
        continue
    if 'k1' in v2:  # 如有字典中已经有k 则追加到k对应的v中
        v2['k1'].append(item)
    else:
        v2['k1'] = [item]  # 新建k , 值为列表  [v]
print(v2)
# {'k1'=[6,7,8,9],}
'''
# 4.简述深浅拷贝？
'''
浅拷贝:仅会拷贝a的框架的内存地址, 里面的任何子元素的内存地址都不会被拷贝.
深拷贝:不仅拷贝a的框架,而且会拷贝a里所有的可变元素的内存地址,注意不可变元素仍不可拷贝
'''

# question 5.看代码写结果
'''
import copy

v1 = "alex"
v2 = copy.copy(v1)
v3 = copy.deepcopy(v1)

print(v1 is v2)
print(v1 is v3)
'''
#Ture
#Ture

# question 6.看代码写结果
'''
import copy

v1 = [1,2,3,4,5]
v2 = copy.copy(v1)
v3 = copy.deepcopy(v1)
print(id(v1),id(v2),id(v3))

print(v1 is v2)
print(v1 is v3)
'''
#False
#False

# question 7.看代码写结果
'''
import copy

v1 = [1,2,3,4,5]

v2 = copy.copy(v1)
v3 = copy.deepcopy(v1)

print(v1[0] is v2[0])
print(v1[0] is v3[0])
print(v2[0] is v3[0])
'''
#Ture
#Ture
#Ture



# question 8.看代码写结果
'''
import copy

v1 = [1,2,3,{"name":'武沛齐',"numbers":[7,77,88]},4,5]

v2 = copy.copy(v1)

print(v1 is v2)   #False

print(v1[0] is v2[0]) #Ture
print(v1[3] is v2[3]) #Ture

print(v1[3]['name'] is v2[3]['name'])   #Ture
print(v1[3]['numbers'] is v2[3]['numbers'])  #Ture
print(v1[3]['numbers'][1] is v2[3]['numbers'][1])  #Ture

'''

# question 9.看代码写结果
'''
import copy

v1 = [1,2,3,{"name":'武沛齐',"numbers":[7,77,88]},4,5]

v2 = copy.deepcopy(v1)

print(v1 is v2)    #False
print(v1[0] is v2[0])  #Ture
print(v1[3] is v2[3])  #False

print(v1[3]['name'] is v2[3]['name'])   #Ture
print(v1[3]['numbers'] is v2[3]['numbers'])  #False
print(v1[3]['numbers'][1] is v2[3]['numbers'][1])  #Ture
'''



# question 10.简述文件操作的打开模式
# file_object = open('aaa.txt',mode = 'r', encoding = 'utf-8') #mode = 'r' 'w' 'a' 'r+' 'w+' 'a+'
# 'r': 只读模式 content = file_object.read()/readline()
# 'w': 只写模式 打开后会清空文件所有内容
# 'a': 追加模式 只能够追加
# 'r+': 可以读写  读的时候从0开始,写的时候从光标处书写,可以使用seek进行调节光标
# 'w+': 可以读写  打开的时候会清空所有内容, 读文件会从写入的文件光标停留处开始读,也可以通过seek进行位置的调整
# 'a+': 可以读写  读的时候从光标处开始,写的时候会自动跳到最后开始写



# question 11.请将info中的值使用 "_" 拼接起来并写入到文件 "readme.txt" 文件中。
'''
info = ['骗子，','不是','说','只有',"10",'个题吗？']
data = "_".join(info)
file_object = open('readme.txt',mode='w',encoding='utf-8')
file_object.write(data)
file_object.close()
'''


#question 12.请将info中的值使用 "_" 拼接起来并写入到文件 "readme.txt" 文件中。
# info = ['骗子，','不是','说','只有',10,'个题吗？']
# info1 = []
# for i in info:
#     i = str(i)
#     info1.append(i)
# print(info1)
# info1 = '_'.join(info1)
#
# file_object = open('readme.txt',mode = 'w',encoding = 'utf-8')
# file_object.write(info1)
# file_object.close()

#question 13.请将info中的值使用 "_" 拼接起来并写入到文件 "readme.txt" 文件中。
info = {'name':'骗子','age':18,'gender':'性别'}
# 1. 请将info中的所有键 使用 "_" 拼接起来并写入到文件 "readme.txt" 文件中。
'''
data=[]
for i in info.keys():
    data.append(i)
data1="_".join(data)
file_object = open('readme.txt',mode='w',encoding='utf-8')
file_object.write(data1)
file_object.close()
'''
# 2. 请将info中的所有值 使用 "_" 拼接起来并写入到文件 "readme.txt" 文件中。
'''
data=[]
for i in info.values():
    data.append(i)
data[1]="18"
data1="_".join(data)
file_object = open('readme.txt',mode='w',encoding='utf-8')
file_object.write(data1)
file_object.close()
'''
# 3. 请将info中的所有键和值按照 "键|值,键|值,键|值" 拼接起来并写入到文件 "readme.txt" 文件中。
'''
info = {'name':'骗子','age':18,'gender':'性别'}
info1=str(info)
print(info1)
data1=info1.replace(':','|')
file_object = open('readme.txt',mode='w',encoding='utf-8')
file_object.write(data1)
file_object.close()
'''


#question 14.要求：如文件 data.txt 中有内容如下：
'''
wupeiqi | oldboy | wupeiqi @ xx.com
alex | oldboy | 66s @ xx.com
xxxx | oldboy | yuy @ xx.com
'''
# 请用代码实现读入文件的内容，并构造成如下格式：
'''
info = [
    {'name': 'wupeiqi', 'pwd': 'oldboy', 'email': 'wupeiqi@xx.com'},
    {'name': 'alex', 'pwd': 'oldboy', 'email': '66s@xx.com'},
    {'name': 'xxxx', 'pwd': 'oldboy', 'email': 'yuy@xx.com'},]
'''
# file_object= open('data.txt',mode='r',encoding='utf-8')
# contend=file_object.read()
# file_object.close()
# contend=contend.strip()
# v1=contend.split('|')
# for i in v1:
#     v2 = {}
#     v3 = []
#     i = i.strip()
#     v3.append(i)
#     v2['name']=v3[0]
#     # v2['pwd']=v3[1]
#     # v2['email']=v3[2]
#     print(v2)








# list1 = []
# file_object = open('readme.txt', mode= 'r',encoding= 'utf-8')
# for i in file_object:
#     info1 = {}
#     list = i.strip().split('|')
#     info1['name'] = list[0]
#     info1['pwd'] = list[1]
#     info1['email'] = list[2]
#     list1.append(info1)
# print(list1)
# file_object.close()


f=open('data.txt',mode='r',encoding='utf8')
# print(f.readlines())
info=[]
for i in f.readlines():
    dic={}
    i=i.strip().split('|')
    dic['name']=i[0]
    dic['pwd'] = i[1]
    dic['email'] = i[2]

    info.append(dic)
print(info)
f.close()